import request from '@/utils/request';

export interface reqCategoryItemType {
  id: number;
  name: string;
  category1Id?: number;
  category2Id?: number;
}

export type reqCategoryType = reqCategoryItemType[];

//1.请求一级分类列表
export const requestCategory1 = () => {
  return request.get<any, reqCategoryType>(`/admin/product/getCategory1`);
};

//2.请求二级分类列表
export const requestCategory2 = (category1Id: number) => {
  return request.get<any, reqCategoryType>(
    `/admin/product/getCategory2/${category1Id}`,
  );
};

//3.请求三级分类列表
export const requestCategory3 = (category2Id: number) => {
  return request.get<any, reqCategoryType>(
    `/admin/product/getCategory3/${category2Id}`,
  );
};
/*--------------------------------*/
//配置属性
export interface attrValueItemType {
  'id'?: number,
  'valueName': string,
  'attrId': number,
  'isEdit'?:boolean
}
export interface attrListValueType {
  'id'?: number,
  'attrName': string,
  'categoryId': number,
  'categoryLevel': number,
  'attrValueList':attrValueItemType[]
}
export type attrListType = attrListValueType[]
//4.请求获取三级分类的属性
export const requestAttrList = (category1Id: number, category2Id: number, category3Id: number) => {
  return request.get<any, attrListType>(
    `/admin/product/attrInfoList/${category1Id}/${category2Id}/${category3Id}`,
  );
};
//5.新增属性的请求
export const requestUpdateOrAddAttr = (newAttr:attrListValueType) => {
  return request.post(`/admin/product/saveAttrInfo`, newAttr);
};
//6.删除属性的请求
export const requestDeleteAttr = (attrId: number) => {
  return request.delete(`/admin/product/deleteAttr/${attrId}`);
};
